﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZX.OA.Model;
namespace ZX.OA.DAL
{
    /// <summary>
    /// 出差功能的操作
    /// </summary>
  public   class EvectionDal
  {
      /// <summary>
      /// EF的链接
      /// </summary>
      Entity entity = new Entity();
      
      /// <summary>
      /// 出差列表的显示
      /// </summary>
      /// <returns></returns>
      public List<EvectionInfo> Show_EvectionInfo()
      {
          return entity.EvectionInfo.ToList();
      }
      /// <summary>
      /// 部门下拉框显示
      /// </summary>
      /// <returns></returns>
      public List<DeptInfo> Drop_DeptInfo()
      {
          return entity.DeptInfo.ToList();
      }
      /// <summary>
      /// 添加请假信息
      /// </summary>
      /// <param name="id"></param>
      /// <returns></returns>
      public int Add_EvectionInfo(EvectionInfo evection)
      {
          entity.EvectionInfo.Add(evection);
          return entity.SaveChanges();
      }
      /// <summary>
      /// 显示出差详情
      /// </summary>
      /// <param name="id"></param>
      /// <returns></returns>
      public EvectionInfo Upd_EvectionInfo(int id)
      {
          return entity.EvectionInfo.Find(id);
      }
      /// <summary>
      /// 撤销出差信息
      /// </summary>
      /// <param name="id"></param>
      /// <returns></returns>
      public int Del_EvectionInfo(int id)
      {
          entity.EvectionInfo.Remove(entity.EvectionInfo.Find(id));
          return entity.SaveChanges();

      }
      /// <summary>
      /// 查询出差信息
      /// </summary>
      /// <param name="EvectionPerson">出差人</param>
      /// <param name="DeptId">部门</param>
      /// <returns></returns>
      public List<EvectionInfo> Sel_EvectionInfo (string EvectionPerson,int ? DeptId)
      {
          return entity.EvectionInfo.Where((p => (string.IsNullOrEmpty(EvectionPerson) ? true : p.EvectionPerson.Contains(EvectionPerson)) || (p.DeptId == null ? true : p.DeptId == DeptId))).ToList();
      }
    }
}
